# 合并字典,相同K时保留v较大者
def merge(d1, d2):
    items = [*d1.items(), *d2.items()]
    d = {}
    for k, v in items:
        if k in d and v <= d.get(k):
            continue
        d[k] = v
    return d


if __name__ == '__main__':
    dict1 = {'a': 10, 'b': 8, 'd': 7}
    dict2 = {'d': 6, 'c': 4}
    # 打印合并结果
    print(merge(dict1, dict2))
